home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / bcfamily / source / viowrite.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-12  |  6.5 KB  |  303 lines

  1. //
  2. //      *******************************************************************
  3. //        JdeBP C++ Library Routines          General Public Licence v1.00
  4. //            Copyright (c) 1991,1992     Jonathan de Boyne Pollard
  5. //      *******************************************************************
  6. //
  7. // Part of FamAPI.LIB
  8. //
  9.  
  10. #include "famapi.h"
  11. #include "vio.h"
  12.  
  13. #pragma argsused
  14. //
  15. //    Write a string of characters in the existing display attributes
  16. //
  17. USHORT _APICALL
  18. VioWrtCharStr ( const char far *PtrString,
  19.                 unsigned short StringLen,
  20.                 unsigned short Row,
  21.                 unsigned short Col,
  22.                 unsigned short VioHandle )
  23. {
  24.     unsigned char far *screen = (unsigned char far *)VioDosPointer(Row, Col) ;
  25.  
  26.     if (!screen) {
  27.         unsigned short savepos = VioDosGetCurPos() ;
  28.         unsigned short pos = (Row << 8) + (Col & 0xFF) ;
  29.  
  30.         while (StringLen--) {
  31.             VioDosSetCurPos (pos++) ;
  32.             asm {
  33.                 mov AH,0x08 ;
  34.                 mov BH,0x00 ;
  35.                 push SI ;
  36.                 push DI ;
  37.                 int 0x10 ;                // Read cell at cursor
  38.                 pop DI ;
  39.                 pop SI ;
  40.                 push AX ;                // Save it
  41.             }
  42.             _AL = *(PtrString)++ ;        // Rewrite with new character
  43.             asm {
  44.                 mov AH,0x0A ;
  45.                 pop BX ;                // Restore cell
  46.                 mov BL,BH ;                // Keep attribute part
  47.                 mov BH,0x00 ;
  48.                 mov CX,0x01 ;
  49.                 push SI ;
  50.                 push DI ;
  51.                 int 0x10 ;                // Write a cell at cursor
  52.                 pop DI ;
  53.                 pop SI ;
  54.             }
  55.         }
  56.         VioDosSetCurPos (savepos) ;
  57.     } else {
  58.         while (StringLen--) {
  59.             *screen = (unsigned char)*PtrString++ ;
  60.             screen += 2;
  61.         }
  62.     }
  63.  
  64.     return NO_ERROR ;
  65. }
  66.  
  67. #pragma argsused
  68. //
  69. //    Write a string of characters in a single display attribute
  70. //
  71. USHORT _APICALL
  72. VioWrtCharStrAtt (    const char far *PtrString,
  73.                     unsigned short StringLen,
  74.                     unsigned short Row,
  75.                     unsigned short Col,
  76.                     const unsigned char far *PtrAttr,
  77.                     unsigned short VioHandle )
  78. {
  79.     unsigned short far *screen = VioDosPointer(Row, Col) ;
  80.  
  81.     if (!screen) {
  82.         unsigned short savepos = VioDosGetCurPos() ;
  83.         unsigned short pos = (Row << 8) + (Col & 0xFF) ;
  84.         unsigned char attr = *PtrAttr & 0x0F;
  85.  
  86.         while (StringLen--) {
  87.             VioDosSetCurPos (pos++) ;
  88.             _AH = 0x09 ;
  89.             _AL = *(PtrString)++ ;        // Modifies ES:BX
  90.             _BH = 0x00 ;
  91.             _BL = attr ;
  92.             _CX = 0x01 ;
  93.             asm {
  94.                 push SI ;
  95.                 push DI ;
  96.                 int 0x10 ;                // Write a cell at cursor
  97.                 pop DI ;
  98.                 pop SI ;
  99.             }
  100.         }
  101.         VioDosSetCurPos (savepos) ;
  102.     } else {
  103.         unsigned short attr = ((unsigned short)*PtrAttr) << 8 ;
  104.         while (StringLen--) {
  105.             *(screen)++ = (unsigned char)*PtrString++ | attr ;
  106.         }
  107.     }
  108.  
  109.     return NO_ERROR ;
  110. }
  111.  
  112. #pragma argsused
  113. //
  114. //    Write a string of character/attribute pairs
  115. //
  116. USHORT _APICALL
  117. VioWrtCellStr ( const char far *PtrCellStr,
  118.                 unsigned short StringLen,
  119.                 unsigned short Row,
  120.                 unsigned short Col,
  121.                 unsigned short VioHandle )
  122. {
  123.     unsigned short far *screen = VioDosPointer(Row, Col) ;
  124.  
  125.     ++StringLen;        // Round upwards
  126.     StringLen >>= 1 ;    // Convert byte count to word count
  127.     if (!screen) {
  128.         unsigned short savepos = VioDosGetCurPos() ;
  129.         unsigned short pos = (Row << 8) + (Col & 0xFF) ;
  130.  
  131.         while (StringLen--) {
  132.             VioDosSetCurPos (pos++) ;
  133.             _AH = 0x09 ;
  134.             _AL = *(PtrCellStr)++ ;        // Character (modifies ES:BX)
  135.             _BL = *(PtrCellStr)++ ;        // Then attribute
  136.             _BH = 0x00 ;
  137.             _CX = 0x01 ;
  138.             asm {
  139.                 push SI ;
  140.                 push DI ;
  141.                 int 0x10 ;                // Write a cell at cursor
  142.                 pop DI ;
  143.                 pop SI ;
  144.             }
  145.         }
  146.         VioDosSetCurPos (savepos) ;
  147.     } else {
  148.         while (StringLen--) {
  149.             *(screen)++ = *((unsigned short far *)PtrCellStr)++ ;
  150.         }
  151.     }
  152.  
  153.     return NO_ERROR ;
  154. }
  155.  
  156. #pragma argsused
  157. //
  158. //    Write an attribute, repeatedly
  159. //
  160. USHORT _APICALL
  161. VioWrtNAttr   ( const unsigned char far *PtrAttr,
  162.                 unsigned short Count,
  163.                 unsigned short Row,
  164.                 unsigned short Col,
  165.                 unsigned short VioHandle )
  166. {
  167.     unsigned char far *screen = (unsigned char far *)VioDosPointer(Row, Col) ;
  168.  
  169.     if (!screen) {
  170.         unsigned short savepos = VioDosGetCurPos() ;
  171.         unsigned short pos = (Row << 8) + (Col & 0xFF) ;
  172.  
  173.         while (Count--) {
  174.             VioDosSetCurPos (pos++) ;
  175.             asm {
  176.                 mov AH,0x08 ;
  177.                 mov BH,0x00 ;
  178.                 push SI ;
  179.                 push DI ;
  180.                 int 0x10 ;                // Read cell at cursor
  181.                 pop DI ;
  182.                 pop SI ;
  183.                 push AX ;
  184.             }
  185.             _BL = *(PtrAttr) ;            // Rewrite with new attribute
  186.             asm {
  187.                 pop AX ;
  188.                 mov    AH,0x09 ;
  189.                 mov BH,0x00 ;
  190.                 mov CX,0x01 ;
  191.                 push SI ;
  192.                 push DI ;
  193.                 int 0x10 ;                // Write a cell at cursor
  194.                 pop DI ;
  195.                 pop SI ;
  196.             }
  197.         }
  198.         VioDosSetCurPos (savepos) ;
  199.     } else {
  200.         while (Count--) {
  201.             screen++ ;
  202.             *screen++ = *(PtrAttr) ;
  203.         }
  204.     }
  205.  
  206.     return NO_ERROR ;
  207. }
  208.  
  209. #pragma argsused
  210. //
  211. //    Write a character/attribute pair, repeatedly
  212. //
  213. USHORT _APICALL
  214. VioWrtNCell   ( const unsigned char far *PtrCell,
  215.                 unsigned short Count,
  216.                 unsigned short Row,
  217.                 unsigned short Col,
  218.                 unsigned short VioHandle )
  219. {
  220.     unsigned short far *screen = VioDosPointer(Row, Col) ;
  221.  
  222.     if (!screen) {
  223.         unsigned short savepos = VioDosGetCurPos() ;
  224.         unsigned short pos = (Row << 8) + (Col & 0xFF) ;
  225.  
  226.         VioDosSetCurPos (pos++) ;
  227.         _AH = 0x09 ;
  228.         _AL = PtrCell[1] ;            // Attribute (modifies ES:BX)
  229.         asm push AX ;
  230.         _AL = PtrCell[0] ;            // Character (modifies ES:BX)
  231.         asm pop BX ;
  232.         _BH = 0x00 ;
  233.         _CX = Count ;
  234.         asm {
  235.             push SI ;
  236.             push DI ;
  237.             int 0x10 ;                // Write CX cells at cursor
  238.             pop DI ;
  239.             pop SI ;
  240.         }
  241.         VioDosSetCurPos (savepos) ;
  242.     } else {
  243.         while (Count--) {
  244.             *screen++ = *((unsigned short far *)PtrCell) ;
  245.         }
  246.     }
  247.  
  248.     return NO_ERROR ;
  249. }
  250.  
  251. #pragma argsused
  252. //
  253. //    Write a character, repeatedly
  254. //
  255. USHORT _APICALL
  256. VioWrtNChar   ( const char far *PtrChar,
  257.                 unsigned short Count,
  258.                 unsigned short Row,
  259.                 unsigned short Col,
  260.                 unsigned short VioHandle )
  261. {
  262.     unsigned char far *screen = (unsigned char far *)VioDosPointer(Row, Col) ;
  263.  
  264.     if (!screen) {
  265.         unsigned short savepos = VioDosGetCurPos() ;
  266.         unsigned short pos = (Row << 8) + (Col & 0xFF) ;
  267.  
  268.         while (Count--) {
  269.             VioDosSetCurPos (pos++) ;
  270.             _AH = 0x08 ;
  271.             _BH = 0x00 ;
  272.             asm {
  273.                 push SI ;
  274.                 push DI ;
  275.                 int 0x10 ;                // Read cell at cursor
  276.                 pop DI ;
  277.                 pop SI ;
  278.             }
  279.             _BL = _AH ;                    // Keep the attribute
  280.             _AH = 0x0A ;
  281.             asm    push BX ;                //
  282.             _AL = *(PtrChar) ;            // Rewrite with new character
  283.             asm pop BX ;
  284.             _BH = 0x00 ;
  285.             _CX = 0x01 ;
  286.             asm {
  287.                 push SI ;
  288.                 push DI ;
  289.                 int 0x10 ;                // Write a cell at cursor
  290.                 pop DI ;
  291.                 pop SI ;
  292.             }
  293.         }
  294.         VioDosSetCurPos (savepos) ;
  295.     } else {
  296.         while (Count--) {
  297.             *screen = *(PtrChar) ;
  298.             screen += 2 ;
  299.         }
  300.     }
  301.  
  302.     return NO_ERROR ;
  303. }